<?php
/**
 * Created by PhpStorm.
 * User: hcadmin
 * Date: 16/7/20
 * Time: 下午3:24
 */
namespace app\models;

use app\common\CommonHelper;
use Yii;
use yii\db\ActiveRecord;
class Attr_opt extends ActiveRecord
{
    public function getCommodityAttributeOptions($attr_opt_ids)
    {
        $commodityAttributeOptions = array();
        foreach($attr_opt_ids as $attr_opt_id){

            $commodityAttributeOption = Attr_opt::find()->where([
                'del_flag'=>1,
                'attr_opt_id' => $attr_opt_id
            ])->asArray()->one();
//            $commodityAttributeOption = CommonHelper::convertObjToArr($commodityAttributeOption);
            if($commodityAttributeOption){
                array_push($commodityAttributeOptions,$commodityAttributeOption);
            }
        }
        return $commodityAttributeOptions;
    }

    //根据属性id获取设置列表
    public function getAttrOptList($attr_id){
        $attrOptList = Attr_opt::find()->where([
            'del_flag'=>1,
            'attr_id' => $attr_id,
        ])->asArray()->all();

        for($i=0;$i<count($attrOptList);$i++) {
            $p_arr= Attr::find()->select(['attr_name'])->where(['attr_id' => $attrOptList[$i]['attr_id']])->asArray()->one();
            $attrOptList[$i]['attr_name']=$p_arr['attr_name'];
        }
        return $attrOptList;
    }

    public function getAttrById($attr_id){
        $attrs = Attr_opt::find()->where([
            'del_flag'=>1,
            'attr_opt_id' => $attr_id
        ])->asArray()->one();
        return $attrs;
    }
}